using System;
using System.Collections;

namespace Sedna.Core.Tiles.Contents
{
	public class ContentCollection : IContentCollection
	{
		private ArrayList contents = new ArrayList();
		private String placeHolderContainerId;

		public void CopyTo(Array array, int index)
		{
			contents.CopyTo(array, index);
		}

		public int Count
		{
			get { return contents.Count;}
		}

		public Object SyncRoot
		{
			get { return contents.SyncRoot;}
		}

		public bool IsEmpty
		{
			get { return (contents.Count == 0);}
		}

		/// <summary>
		/// On <c>set</c> <c>ICollection</c> the new instance of the underlying collection is creating
		/// </summary>
		public ICollection Contents
		{
			get { return ArrayList.ReadOnly(contents);}
			set
			{
				contents = new ArrayList();

				if (value != null)
				{
					foreach (Object element in value)
					{
						if ((element is IContent) || (element is IContentCollection))
						{
							contents.Add(element);
						}
					}
				}				
			}
		}

		public String PlaceHolderContainerId
		{
			get { return placeHolderContainerId;}
			set { placeHolderContainerId = value;}
		}

		public void Clear()
		{
			contents.Clear();
		}

		public bool IsSynchronized
		{
			get { return contents.IsSynchronized;}
		}

		public IEnumerator GetEnumerator()
		{
			return contents.GetEnumerator();
		}
	}
}
